package com.yc.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yc.entity.Schedule;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * (schedule课程表、school_year周次表)表数据库访问层
 * @date : 2023-8-2
 */
@Mapper
public interface WxScheduleMapper {


    /**
     *
     * @param week 当前的周次
     * @param tid 老师的id（工号
     * @return 课程id 课程名 第几节 班级名 教室 上课时间 显示的颜色
     */
    @Select(" select *,(select GROUP_CONCAT(DISTINCT week) from schedule a where teacherId = temp.teacherId and classId =temp.cid and classroom =temp.classroom and \n" +
            "classtime =temp.classtime and coursename = temp.coursename ) as classweek from ( SELECT a.id,a.coursename,a.date,d.cname,a.classroom,a.classtime,a.colour,b.id as teacherId,d.id as cid FROM  \n" +
            "`schedule` a,systemuser b,class_info d  WHERE a.teacherId=b.id and a.classId = d.id AND a.`week`=#{week} AND b.username=#{tid} ) temp ")
    List<Map<String,Object>> selectteaclass(@Param("week") String week,
                                            @Param("tid") String tid);

    /**
     * 学生查询课程
     * @param week 当前的周次
     * @param stuid 学生的id（学号
     * @return 课程id 课程名 第几节 老师名 教室 上课时间 显示的颜色
     */
    @Select(" select *,(select GROUP_CONCAT(DISTINCT week) from schedule a  where teacherId = temp.teacherId and classId =temp.classId  and classroom =temp.classroom and classtime =temp.classtime and coursename = temp.coursename ) as classweek from\n" +
            "            (select a.id,a.coursename,a.date,b.nickname,a.classroom,a.classtime,a.colour,b.id as teacherId,c.cid as classId FROM  `schedule` a left join student_info c on c.cid = a.classId left join systemuser b on a.teacherId=b.id\n" +
            "             WHERE a.`week`=#{week} AND c.stuid=#{stuid} ) temp ")
    List<Map<String,Object>> selectstuclass(@Param("week") String week,
                                            @Param("stuid") String stuid);

    /**
     * 查询学年
     * @return
     */
    @Select("SELECT DISTINCT a.school_year FROM school_year a")
    List<Map<String,Object>> selectschoolyear();

    @Select("SELECT DISTINCT `week` FROM school_year a WHERE school_year=#{year}")
    Map<String,Object> selectweek(@Param("year") String year);

    /**
     * 查询当天是哪个学期的哪一周
     * @param day
     * @return
     */
    @Select("SELECT `week`,school_year FROM school_year WHERE time=#{day}")
    Map<String,Object> selectwhichweekandyear(@Param("day") String day);

    /**
     * 查询该周次下的日期
     * @param week 查询的周次
     * @param year 查询的学期
     * @return
     */
    @Select("SELECT a.time FROM school_year a WHERE `week`=#{week} AND a.school_year=#{year} ")
    List<String> selectalldayinthisweek(@Param("week") String week,
                                        @Param("year") String year);

}
